<?php
App::uses( 'MemberAppModel', 'Model');

class Bill extends AppModel {
    var $name = 'Bill';

    var $validate = array(
        'name_from' => array(
            'notempty' => array(
                'rule' => array('notempty'),
                'message' => 'Name is not null',
                'allowEmpty' => false,
                'required' => true,
            ),

            'maxlength' => array(
                'rule' => array('maxlength', 255),
                'message' => 'Name not more than 255 characters',
                'allowEmpty' => false,
                'required' => true,
            ),
        ),

        'phone_from' => array(
            'notempty' => array(
                'rule' => array('notempty'),
                'message' => 'Phone is not null.',
                'allowEmpty' => false,
                'required' => true,
            ),
        ),

        'address_to' => array(
            'notempty' => array(
                'rule' => array('notempty'),
                'message' => 'Address is not null',
                'allowEmpty' => false,
                'required' => true,
            ),

            'maxlength' => array(
                'rule' => array('maxlength', 255),
                'message' => 'Address not more than 255 characters',
                'allowEmpty' => false,
                'required' => true,
            ),
        ),
    );





    /**
	 * Get all
	 *
	 * @param type  meta
	 * @return type  meta
	 * @access public
	 */
	function getAll(){
		return $this->find('all', array(
			'conditions' => array(
				'status' => 4,
				'company_id' => @$_SESSION['current_company']['id']
			)
		));
	}

	/**
	 * Get info by id
	 *
	 * @param type  meta
	 * @return type  meta
	 * @access public
	 */
	function getInfoById($id = null){
		if(empty($id)) return array();

		return $this->find('first', array(
			//'fields' => array('id', 'name', 'discounts', 'desc', 'price', 'image', 'category_id'),
			'conditions' => array(
				'id' => $id,
				'status' => 4,
				'company_id' => @$_SESSION['current_company']['id']
			)
		));
	}


}
